import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';

class UrlLaunchUtil {
  static UrlLaunchUtil? _instance;

  factory UrlLaunchUtil() {
    _instance ??= UrlLaunchUtil._init();
    return _instance!;
  }

  UrlLaunchUtil._init();

  Future<void> launchTel({required String mobile}) async {
    final res = await canLaunchUrl(Uri(scheme: 'tel', path: mobile));
    debugPrint("res=$res");
    if (!res) return;
    await launchUrl(Uri(scheme: 'tel', path: mobile));
  }

  Future<void> launchSms({required String mobile}) async {
    final res =
        await canLaunchUrl(Uri(scheme: 'sms', path: mobile, queryParameters: {
      'body': "",
    }));
    debugPrint("res=$res");
    if (!res) return;
    await launchUrl(Uri(scheme: 'sms', path: mobile, queryParameters: {
      'body': "",
    }));
  }
}
